package com.doit.day01;

import org.apache.commons.lang3.RandomUtils;
import redis.clients.jedis.Jedis;

import java.util.Random;

public class ConsumerDemo1 {
    public static void main(String[] args) throws InterruptedException {
        Jedis jedis = new Jedis("linux01", 6379);

        Random random = new Random();

        while (true){
            int num = random.nextInt(1000);
            //消费缓存里面的task
            String task = jedis.rpop("cache");
            if (num %3 == 0){
                //这个任务是失败的
                jedis.lpush("cache",task);
                System.out.println("task执行失败，重新放回到缓冲区"+task);
            }else{
                System.out.println("task执行成功"+task);
            }
            Thread.sleep(RandomUtils.nextInt(1000,3000));
        }
    }
}
